//function to validate tournament form
var validateTournament = function(){
	
	
	//function to clear team divs
	clearTournamentDivs();
	
	var name       = document.getElementById('name').value;
	var country    = document.getElementById('country').value;
	var startDate  = document.getElementById('start_date').value;
	var endDate    = document.getElementById('end_date').value;
	//var noOfTeam   = document.getElementById('no_of_team').value;
	var caption    = document.getElementById('caption').value;
	var type       = document.getElementById('type').value;
	var team       = document.getElementById('team').value;
	var teamDrp	   = document.getElementsByName('team[]');
	
	var counter = 0;
	if(name == "")
	{
		document.getElementById('divName').innerHTML =  "<span class='error'>Please Enter Team Name</span>";
		counter = counter + 1;
	}
	if(country == "")
	{
		document.getElementById('divCountry').innerHTML =  "<span class='error'>Please Select  Country</span>";
		counter = counter + 1;
	}
	if(startDate == "")
	{
		document.getElementById('divStartDate').innerHTML =  "<span class='error'>Please Enter Start Date</span>";
		counter = counter + 1;
	}
	if(endDate == "")
	{
		document.getElementById('divEndDate').innerHTML =  "<span class='error'>Please Enter End Date</span>";
		counter = counter + 1;
	}
	/*if(noOfTeam == "")
	{
		document.getElementById('divNoOFTeam').innerHTML =  "<span class='error'>Please Enter Number of Team</span>";
		counter = counter + 1;
	}
	else
	{
		if (!IsNumeric(noOfTeam))
		{
			
			document.getElementById('divNoOFTeam').innerHTML = "<span class='error'>Please Enter Number Only</span>";
			  counter=counter+1;
			
		}
	}*/
	if(caption == "")
	{
		document.getElementById('divCaption').innerHTML =  "<span class='error'>Please Enter Caption</span>";
		counter = counter + 1;
	}
	if(type == 0)
	{
		document.getElementById('divType').innerHTML =  "<span class='error'>Please Enter Type</span>";
		counter = counter + 1;
	}
	if(team == 0)
	{
		document.getElementById('divTeam').innerHTML = "<span class='error'>Please Select Teams</span>";
		counter = counter + 1;
	}
	
	//
	/*var myList = document.getElementById("team");
    var myListLength = myList.options.length; // number of items
    var myListCount  = 0;
    var textToDisplay = "";
    for (i=0; i < myListLength; i++) 
    {
    	if (myList.options[i].selected == true)
    	{
    		myListCount = myListCount + 1;
    	}
    	
    }*/
      
   /*	if(myListCount > noOfTeam || myListCount < noOfTeam)
   	{
    		document.getElementById('divTeam').innerHTML = "<span class='error'>Please Select Only "+noOfTeam+" Teams</span>";
    		counter = counter + 1;
   	}
   	*/

	if(counter > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
};

//function to clear divs of tournament

var clearTournamentDivs = function()
{
	document.getElementById('divName').innerHTML 		=  "";
	document.getElementById('divCountry').innerHTML 	=  "";
	document.getElementById('divStartDate').innerHTML   =  ""; 
	document.getElementById('divEndDate').innerHTML     =  "";
	//document.getElementById('divNoOFTeam').innerHTML    =  "";
	document.getElementById('divCaption').innerHTML     =  "";
	document.getElementById('divType').innerHTML 		=  "";
	document.getElementById('divTeam').innerHTML 		=  "";
	
};

//This function is used to check the string is Numeric
function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}

//function to validate team to tournament 
function validateTeamTournament()
{
	clearTournamentTeanDiv();
	var tournament = document.getElementById('tournament').value;
	var team       = document.getElementById('team').value;
	
	
	var counter    = 0;
	if(tournament == 0)
	{
		document.getElementById('divTournament').innerHTML = "<span class='error'>Please Select Tournament</span>";
		counter = counter + 1;
		
	}
	if(team == 0)
	{
		document.getElementById('divTeam').innerHTML = "<span class='error'>Please Select Teams</span>";
		counter = counter + 1;
	}
	
	if(counter > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//function clearDivsTeamTournament

function clearTournamentTeanDiv()
{
	document.getElementById('divTournament').innerHTML = "";
	document.getElementById('divTeam').innerHTML = "";
	
}
